package com.example.club.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.club.R
import com.example.club.model.RecommendClub

class RecommendClubAdapter(private val data: List<RecommendClub>) : RecyclerView.Adapter<RecommendClubAdapter.ViewHolder>() {

    class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val ivClub: ImageView = itemView.findViewById(R.id.iv_club)
        val tvName: TextView = itemView.findViewById(R.id.tv_club_name)
        val tvDesc: TextView = itemView.findViewById(R.id.tv_club_desc)
        val ratingBar: RatingBar = itemView.findViewById(R.id.rating_bar)
        val tvMember: TextView = itemView.findViewById(R.id.tv_club_count)
        val tvDistance: TextView = itemView.findViewById(R.id.tv_club_distance)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_recommend_club_full, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = data[position]
        holder.ivClub.setImageResource(item.imageRes)
        holder.tvName.text = item.name
        holder.tvDesc.text = item.desc
        holder.ratingBar.rating = item.rating
        holder.tvMember.text = item.memberCount.toString()
        holder.tvDistance.text = "${item.distance}km"
    }

    override fun getItemCount() = data.size
} 